#include<bits/stdc++.h>
using namespace std;
const long long mx1=1e5*2+5,mx2=1e6;
long long n,a[mx1],b[mx2],sum;
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
        cin>>n;
        sum=0;
        memset(a,0,sizeof(a)),memset(b,-1,sizeof(b));
        for(int i=1;i<=n;i++) cin>>a[i],b[a[i]]++;
        sort(a+1,a+n+1);
        for(int i=1;i<=n;i++) sum+=b[a[i]]*a[i],b[a[i]]=0;
        cout<<sum<<endl;
    }
    return 0;
}
